home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / StereoScope / Source / StereoController.m < prev    next >
Text File  |  1994-04-01  |  5KB  |  228 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "StereoController.h"
  5. #import "StereoView.h"
  6. #import "Help.h"
  7. #import "DefaultHandler.h"
  8. #import "SterOptikonApp.h"
  9. #import <appkit/Application.h>
  10. #import <appkit/Listener.h>
  11. #import <appkit/Pasteboard.h>
  12. #import <appkit/OpenPanel.h>
  13. #import <appkit/ScrollView.h>
  14. #import <appkit/Text.h>
  15. #import <appkit/TextField.h>
  16. #import <stdlib.h>
  17. #import <strings.h>
  18. #import <string.h> 
  19. #import <stdio.h>
  20. #import <math.h>
  21. #include <mach.h>
  22.  
  23. int    isCleared;
  24.  
  25. @implementation StereoController
  26.  
  27. id _defaults;
  28. extern char TmpDir[];
  29. extern char EyeOffset[];
  30. extern char Cube[];
  31. extern char Axes[];
  32.  
  33. #include "monitor.m"
  34.  
  35. - appDidInit:sender
  36. {
  37.     float floatVal;
  38.     int    intVal;
  39.  
  40.     inputText = [theScrollView docView];
  41.     [inputText setDelegate:self];
  42.     [[NXApp appListener] setServicesDelegate:self];
  43.  
  44.     [[theStereoView window] makeKeyAndOrderFront:self];
  45. /*
  46.     Get default values and send them to theStereoView
  47.  
  48.     _defaults = [DefaultHandler new];
  49.  
  50.     if (strcmp(EyeOffset,""))    {
  51.         sscanf(EyeOffset,"%f",&floatVal);
  52.         [theStereoView setEyeOffset:floatVal];
  53.         }
  54.     if (strcmp(Axes,""))    {
  55.         sscanf(Axes,"%d",&intVal);
  56.         [theStereoView setAxes:intVal];
  57.         }
  58.     if (strcmp(Cube,""))    {
  59.         sscanf(Cube,"%d",&intVal);
  60.         [theStereoView setCube:intVal];
  61.         }
  62. /**/
  63.     isCleared = NO;
  64.     [theStereoView S_Reset:self];
  65.     {
  66.     char *openFileName;
  67.  
  68.     if (strcmp((openFileName = [NXApp getInitialFile]),""))    {
  69.         [theStereoView readSData:openFileName];
  70.         strcpy(openFileName,"");
  71.     }
  72. }
  73.  
  74.     return self;
  75. }
  76.  
  77. - requestPlot:(id)pasteboard userData:(const char *)userData error: (char **)msg
  78. /*
  79.  * Responds to a request from another application for the plotting service.
  80.  * PlotController copies the data from the supplied pasteboard into the Text object
  81.  * and then sends a plot: message to the StereoView.
  82.  */
  83. {
  84.     char    *data, *scratch;
  85.     int     length;
  86.  
  87.     [NXApp activateSelf:NO]; 
  88.     [pasteboard types];
  89.     if ([pasteboard readType:NXAsciiPboardType data:&data length:&length]) {
  90.         if(scratch = malloc(length+1)) {
  91.             strncpy(scratch, data, length);
  92.             scratch[length]='\0';
  93.             [[inputText selectAll:self] replaceSel:scratch];
  94.             free(scratch);
  95.         }
  96.         vm_deallocate(task_self(), (vm_address_t)data, (vm_size_t)length);
  97.         [theStereoView S_Reset:self];
  98.         [theStereoView textChanged:self];
  99.         [theStereoView plot:self];
  100.     }
  101.     return self;
  102. }
  103.  
  104.  
  105. - quit:sender
  106. {
  107. /*
  108.     sprintf(EyeOffset,"%f",[theStereoView getEyeOffset]);
  109.     sprintf(Axes,"%d",[theStereoView getAxes]);
  110.     sprintf(Cube,"%d",[theStereoView getCube]);
  111.     [_defaults free];
  112. */
  113.     [theStereoView closeRequest:self];
  114.     [NXApp terminate:self];
  115.     return self;
  116. }
  117.  
  118. - showInfoPanel:sender
  119. {
  120.     if(!infoPanel)    {
  121.         [NXApp loadNibSection:"Info.nib" owner:self];
  122.     }
  123.     [infoPanel makeKeyAndOrderFront:self];
  124.     return self;
  125. }
  126.  
  127. - showHelpPanel:sender
  128. {
  129.     if(!helpPanel)
  130.         helpPanel = [[Help alloc] init];
  131.     [helpPanel generalHelp:self];
  132.     return self;
  133. }
  134.  
  135. - showPrefPanel:sender
  136. {
  137.     [prefPanel makeKeyAndOrderFront:self];
  138.     return self;
  139. }
  140.  
  141. - windowDidResize:sender
  142. {
  143. /*    This is received after resizing */
  144. /*    printf("windowDidResize in controller\n");
  145. */
  146.     return self;
  147. }
  148.  
  149. - windowWillResize:sender toSize:(NXSize *)aSize
  150. {
  151. /*    This is received upon mouse down in resize bar */
  152. /*    printf("windowWillResize for controller\n");
  153. */
  154.     return self;
  155. }
  156.  
  157. - showError:(char *)errorMessage
  158. {
  159.   NXRunAlertPanel("Error", errorMessage, "OK", NULL, NULL);
  160.   return self;
  161. }
  162.  
  163. - textDidGetKeys:theText isEmpty:(BOOL)flag
  164. /*
  165.  * Responds to a message the Text object sends when its text changes.
  166.  * StereoController causes the StereoView to clear itself when the text changes.
  167.  */
  168. {
  169.     if ( isCleared ) return self;
  170.     isCleared = YES;
  171.     [theStereoView textEdited:self];
  172.     return [theStereoView clear:self];
  173. }
  174.  
  175. - stereoView:sender providePoints:(NXStream **)stream
  176. /*
  177.  * Responds to a message the PlotView sends requesting the points to plot.  
  178.  * PlotController responds by giving the PlotView access to the Text 
  179.  * object's stream.
  180.  */
  181. {
  182.     int    endPos;
  183.  
  184.     endPos = [inputText byteLength];
  185.     [inputText setSel:endPos :endPos];
  186.     *stream = [inputText stream];
  187.     [[theStereoView window] makeFirstResponder:theStereoView];
  188.     isCleared = NO;
  189.     return self;
  190. }
  191.  
  192. - stereoView:sender pointDidChange:(char *)aLine
  193. /*
  194.  * Responds to a message the StereoView sends notifying its delegate 
  195.  * that a line has been read.  Responds by adding the line to
  196.  * the end of the list in the Text object.
  197.  */
  198. {
  199.     int    endPos;
  200.     char    buffer[100];
  201.  
  202.     sprintf(buffer, "%s\n", aLine);
  203.     endPos = [inputText byteLength];
  204.     [inputText setSel:endPos :endPos];
  205.     [inputText scrollSelToVisible];
  206.     [inputText replaceSel:buffer];
  207.     return self;
  208. }
  209.  
  210. - stereoView:sender clearText:(char *)aLine
  211. /*
  212.  * Responds to a message the StereoView sends notifying its delegate 
  213.  * to clear the text.
  214.  */
  215. {
  216.     int    endPos, beginPos;
  217.  
  218.     endPos = [inputText byteLength];
  219.     beginPos = 0;
  220.     [inputText setSel:beginPos :endPos];
  221.     [inputText scrollSelToVisible];
  222.     [inputText replaceSel:""];
  223.     [[theStereoView window] makeFirstResponder:theStereoView];
  224.     return self;
  225. }
  226.  
  227. @end
  228.